#ifndef CLIENT_REQUEST_QUEUE_H_
#define CLIENT_REQUEST_QUEUE_H_
#include <queue>
#include <boost/noncopyable.hpp>
#include <boost/function.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/shared_ptr.hpp>
#include "gen-cpp/ChatService.h"
namespace client {
  class RequestQueue : public boost::noncopyable {
 public:
    static RequestQueue* Instance();
    static void Create(boost::shared_ptr<chat::ChatServiceClient> client);
    boost::function<void ()> Pop();
    template<typename ReqType>
        void Schedule(const ReqType& req);
 protected:
    RequestQueue(boost::shared_ptr<chat::ChatServiceClient> client);
 private:
    bool IsQueueFull() const;
 private:
    boost::mutex mutex_;
    boost::condition_variable cond_;
    static RequestQueue* self_;
    boost::shared_ptr<chat::ChatServiceClient> client_;
    std::queue<boost::function<void ()> > queue_;
    const static size_t kMaxPendingReq = 20;
  };

}
#endif
